<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>calculator</title>
</head>
<body>
<button onclick="alert('警告！')">警告</button>
<button onclick="confirm('您确认要充值吗？')">确认框</button>
<button onclick="prompt('请输入二级密码:')">提示输入框</button>
<hr>
<input type="text" placeholder="请输入数字1：" id="d1">
<input type="text" placeholder="请输入数字2：" id="d2">
<button onclick="calc('+')">加</button>
<button onclick="calc('-')">减</button>
<button onclick="calc('*')">乘</button>
<button onclick="calc('/')">除</button>
<h4>运算结果: <span></span></h4>
<script>
    function calc(s){
        var inputE1 = document.querySelector('#d1');
        var inputE2 = document.querySelector('#d2');
        var span1 = document.querySelector('span');

        switch (s){
            case '+':
                span1.innerHTML=parseFloat(inputE1.value)+parseFloat(inputE2.value);
                break;
            case '-':
                span1.innerHTML=parseFloat(inputE1.value)-parseFloat(inputE2.value);
                break;
            case '*':
                span1.innerHTML=parseFloat(inputE1.value)*parseFloat(inputE2.value);
                break;
            case '/':
                if(!parseFloat(inputE2.value))
                {
                    alert("除数不能为0！")
                }
                else{
                    span1.innerHTML=parseFloat(inputE1.value)/parseFloat(inputE2.value);
                }

        }
    }




</script>
</body>
</html>